# Maintainer: Daurnimator <daurnimator@archlinux.org>

pkgname=('lua-psl' 'lua51-psl' 'lua52-psl' 'lua53-psl')
pkgver=0.3
pkgrel=3
arch=('loong64' 'x86_64')
pkgdesc='libpsl bindings for Lua'
url='https://github.com/daurnimator/lua-psl'
license=('MIT')
makedepends=('luarocks' 'lua' 'lua51' 'lua52' 'lua53')
depends=('libpsl')
source=("$pkgname-$pkgver.tar.gz::https://github.com/daurnimator/lua-psl/archive/v$pkgver.tar.gz")
sha256sums=('c7d529d33fcd9d898668014d174ed1dc1257e9076da98729d94a4e8b8d231d40')

build() {
  cd "lua-psl-$pkgver"
  for v in 5.1 5.2 5.3 5.4; do
    mkdir -p "$v/"
    luarocks make --pack-binary-rock --lua-version="$v" --deps-mode=none \
      CFLAGS="$CPPFLAGS $CFLAGS -fPIC" \
      LIBFLAG="$LDFLAGS -shared" \
      psl-"$pkgver"-0.rockspec
    mv psl-"$pkgver"-0.*.rock "$v/"
  done
}

package_lua-psl() {
  pkgdesc="$pkgdesc 5.4"

  cd "lua-psl-$pkgver"
  luarocks install --lua-version=5.4 --tree="$pkgdir/usr/" --deps-mode=none 5.4/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua51-psl() {
  pkgdesc="$pkgdesc 5.1"

  cd "lua-psl-$pkgver"
  luarocks install --lua-version=5.1 --tree="$pkgdir/usr/" --deps-mode=none 5.1/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua52-psl() {
  pkgdesc="$pkgdesc 5.2"

  cd "lua-psl-$pkgver"
  luarocks install --lua-version=5.2 --tree="$pkgdir/usr/" --deps-mode=none 5.2/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua53-psl() {
  pkgdesc="$pkgdesc 5.3"

  cd "lua-psl-$pkgver"
  luarocks install --lua-version=5.3 --tree="$pkgdir/usr/" --deps-mode=none 5.3/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
